#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
using namespace std;

long long T,n,m,L,V,d[100005],v[100005],a[100005],p[100005],k[100005],sum[100005],an[100005],l,r,ans;
bool b1,b2,b3;

void find0(long long x){
    long long ret=(V*V-v[x]*v[x])/(2*a[x])+d[x];
    long long k;
    if(V>v[x]){
        return;
    }else if(ret>p[m]){
        k=m;
    }else{
        k=lower_bound(p,p+m+2,ret)-p-1;
    }
    long long k1;
    if(d[x]>p[m]){
        k1=m+1;
    }else{
        k1=lower_bound(p,p+m+2,d[x])-p;
    }
    if(k>=k1){
        ans++;
        sum[k1]++;
        sum[k+1]--;
        //cout<<x<<"\n";
        //cout<<k1<<" "<<k+1<<"\n";
    }
}

void find1(long long x){
    long long ret=(V*V-v[x]*v[x])/(2*a[x])+d[x];
    long long k;
    if(V<v[x]){
        k=lower_bound(p,p+m+2,d[x])-p;
    }else if(ret>p[m]){
        k=m+1;
    }else{
        k=upper_bound(p,p+m+2,ret)-p;
    }
    if(k<=m){
        ans++;
        sum[k]++;
        sum[m+1]--;
        //cout<<x<<"\n";
        //cout<<k<<" "<<m+1<<"\n";
    }
}

void fun(long long x){
    long long k;
    if(d[x]>p[m]){
        k=m+1;
    }else{
        k=lower_bound(p,p+m+2,d[x])-p;
    }
    if(k<=m){
        ans++;
        sum[k]++;
        sum[m+1]--;
        //cout<<x<<"\n";
        //cout<<k<<" "<<m+1<<"\n";
    }
}

int main(){
    //cin.tie(0);
    //cout.tie(0);
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    cin>>T;
    while(T--){
        cin>>n>>m>>L>>V;
        for(int i=1;i<=n;i++){
            cin>>d[i]>>v[i]>>a[i];
        }
        for(int i=1;i<=m;i++){
            cin>>p[i];
        }
        p[0]=-1;
        p[m+1]=2000005;
        ans=0;
        for(int i=1;i<=n;i++){
            if(a[i]<0){
                find0(i);
                b1=true;
            }
            if(a[i]>0){
                find1(i);
                b2=true;
            }
            if(a[i]==0){
                if(v[i]>V){
                    fun(i);
                }
                b3=true;
            }
        }
        cout<<ans<<" ";
        if(b1==false){
            if(ans){
                cout<<"1\n";
            }else{
                cout<<"0\n";
            }
            continue;
        }
        ans=0;
        for(int i=1;i<=m;i++){
            an[i]=an[i-1]+sum[i];
            sum[i-1]=0;
            if(an[i]==0){
                ans++;
                //cout<<i<<" ";
            }
        }
        sum[m]=0;
        sum[m+1]=0;
        //cout<<"\n";
        cout<<ans<<"\n";
    }


	return 0;
}
